home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 151-175 / disk_166 / autograf / options.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  194 lines

  1. /*
  2.      options.c : Options input prossing and support subroutines
  3.                  (Part of Autograf)
  4.  
  5.      By Joel Swank September 3, 1988
  6.      Version 1.0
  7.  
  8.      */
  9.  
  10. #include <intuition/intuition.h>
  11. #include <intuition/intuitionbase.h> 
  12. #include <graphics/gfxbase.h> 
  13. #include <graphics/gfx.h> 
  14. #include <graphics/gfxmacros.h> 
  15. #include <graphics/display.h> 
  16. #include <graphics/text.h> 
  17. #include <ctype.h> 
  18. #include "optwind.h"
  19.  
  20. #ifdef NULL
  21. #undef NULL
  22. #endif
  23. #define NULL ((void *)0)
  24.  
  25. /*************
  26.  
  27.  *  Hooks to the rest of the program
  28.  
  29.  *************/
  30.  
  31. #define MenuList1 Menu1
  32.  
  33. extern struct IntuiText OptText1;
  34. extern struct Menu Menu1;
  35. extern struct Window    *Wind;
  36. extern struct RastPort *rp;
  37.  
  38. /* flags for which grafs to display */
  39. extern int cpm;
  40. extern int ppg;
  41. extern int mpg;
  42.  
  43. extern int syr;        /* for requested start year */
  44. extern int eyr;        /* for requested end year */
  45.  
  46. /* list of the gadgets on the options window */
  47. struct Gadget *gadlist[10] = { &Gadget1, &Gadget2, &Gadget3, &Gadget4, 
  48.                     &Gadget5, &Gadget6, &Gadget7, NULL };
  49.  
  50. /*
  51.  * get_opt : get options via option window
  52.  *
  53.  */
  54.  
  55. get_opt()
  56. {
  57.     int tyr, i;
  58.     struct IntuiMessage    *msg;
  59.     UWORD code;
  60.     ULONG class;
  61.     APTR object;
  62.  
  63.     ClearMenuStrip(Wind);
  64.     SetWindowTitles(Wind,(UBYTE *) "AutoGraf Options Selection", -1L);
  65.     clr_grf();
  66.  
  67.     PrintIText(rp,&IntuiTextList1,0L,0L);    /* Print the gadget text */
  68.     PrintIText(rp,&OptText1,0L,0L);    /* Print the support text */
  69.  
  70.     i=0;
  71.     while (gadlist[i] != NULL)
  72.         {
  73.         AddGadget(Wind,gadlist[i],(USHORT) ~0);
  74.         i++;
  75.         }
  76.     RefreshGadgets(gadlist[0],Wind,0L);
  77.  
  78.     while (1) {
  79.     Wait(1L<<Wind->UserPort->mp_SigBit );
  80.     while(msg = (struct IntuiMessage *) GetMsg(Wind->UserPort)) {
  81.         code = msg->Code;  /* MENUNUM */
  82.         object = msg->IAddress;  /* Gadget */
  83.         class = msg->Class;
  84.         switch(class) {
  85.             case CLOSEWINDOW:
  86.                 ReplyMsg(msg);
  87.                 done(0);
  88.             case GADGETUP:
  89.                 clr_msg();
  90.                 if (Gadget3.Flags & SELECTED) cpm = TRUE;
  91.                     else cpm = FALSE;
  92.                 if (Gadget5.Flags & SELECTED) ppg = TRUE;
  93.                     else ppg = FALSE;
  94.                 if (Gadget4.Flags & SELECTED) mpg = TRUE;
  95.                     else mpg = FALSE;
  96.                 if (Gadget6.Flags & SELECTED) 
  97.                     {
  98.                     ppg = TRUE;
  99.                     cpm = TRUE;
  100.                     mpg = TRUE;
  101.                     }
  102.                 if (Gadget1SIBuff[0] == '\0') syr = -1;
  103.                     else
  104.                     if ((tyr = val_yr(Gadget1SIBuff)) == -1)
  105.                         {
  106.                         lite_msg();
  107.                         PrintIText(rp,&ErrText1,0L,0L);
  108.                         break;
  109.                     }else 
  110.                         {
  111.                         syr = tyr;
  112.                         }
  113.                 if (Gadget2SIBuff[0] == '\0') eyr = -1;
  114.                     else
  115.                     if ((tyr = val_yr(Gadget2SIBuff)) == -1)
  116.                         {
  117.                         lite_msg();
  118.                         PrintIText(rp,&ErrText2,0L,0L);
  119.                         break;
  120.                     }else  {
  121.                         eyr = tyr;
  122.                         if (syr != -1 && syr > eyr)
  123.                             {
  124.                             lite_msg();
  125.                             PrintIText(rp,&ErrText3,0L,0L);
  126.                             break;
  127.                             }
  128.                         }
  129.                 if (msg->IAddress == &Gadget7) goto Dun;  /* OK button */
  130.             case REFRESHWINDOW:
  131.                 break;
  132.         }
  133.         ReplyMsg(msg);
  134.     }
  135.     }    /* end while(Wait())    */
  136.   Dun:
  137.     i=0;
  138.     while (gadlist[i] != NULL)
  139.         {
  140.         RemoveGadget(Wind,gadlist[i]);
  141.         i++;
  142.         }
  143.  
  144.     if (mpg == FALSE && ppg == FALSE && cpm == FALSE) ppg = TRUE;
  145.     SetMenuStrip(Wind,&MenuList1);
  146.     clr_grf();
  147. }
  148.  
  149. /*
  150.  * lite_msg : Set the err-message area of the window to white
  151.  *
  152.  */
  153. lite_msg()
  154. {
  155.     SetAPen(rp,1L);
  156.     RectFill(rp, XOPT+4L, YOPT+3L,XOPT+155L,YOPT+13L);
  157.     SetAPen(rp,3L);
  158. }
  159.  
  160. /*
  161.  * clr_msg : clear the err-message area of the screen
  162.  *
  163.  */
  164. clr_msg()
  165. {
  166.     SetAPen(rp,0L);
  167.     RectFill(rp, XOPT+4L, YOPT+3L,XOPT+155L,YOPT+13L);
  168.     SetAPen(rp,3L);
  169. }
  170.  
  171.  
  172. /*
  173.  * val_yr : validate a year string gadget contents and return
  174.  *          -1 if invalid or year if valid.
  175.  */
  176.  
  177. val_yr(buffer)
  178. char *buffer;
  179. {
  180.     int yr;
  181.     char *bufp;
  182.     bufp = buffer;
  183.     while (*bufp != '\0')
  184.         {
  185.         if (!isdigit(*bufp)) return -1;
  186.         bufp++;
  187.         }
  188.     yr = atoi(buffer);
  189.     if (yr <100 && yr >= 0) return yr+1900;
  190.     if (yr <2200 && yr >= 1900) return yr;
  191.     return -1;
  192. }
  193.  
  194.